﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Net;
using System.Threading;

namespace Test_cmd
{
    class Program
    {
        static void Main(string[] args)
        {
            #region 03-04
            /* Console.WriteLine("请输入：");
             string str = Console.ReadLine();
             Console.WriteLine("登录用户：" + str);
             Console.ReadLine();*/
            #endregion

            #region 03-05
            /*int c=89,csharp=90,sql = 60;
            int sub = csharp - sql;
            double avg = (c + csharp + sql) / 3;
            Console.WriteLine("C#课与sql课的分数差："+sub);
            Console.WriteLine("3门课的平均分"+avg);
            Console.ReadLine();*/
            #endregion

            #region 03-06
            /*int num1 = 4, num2 = 7, num3 = 7;
            Console.WriteLine("num1="+ num1 + "   num2="+ num2+ "  num3="+ num3);
            Console.WriteLine(" num1 < num2的结果"+ (num1 < num2));
            Console.WriteLine(" num1 > num2的结果"+(num1 > num2));
            Console.WriteLine("num1 == num2的结果"+(num1 == num2));
            Console.WriteLine("num1 != num2的结果"+(num1 != num2));
            Console.WriteLine("num1 <= num2的结果"+(num1 <= num2));
            Console.WriteLine("num2 >= num3的结果"+(num2 >= num3));
            Console.ReadLine();*/
            #endregion

            #region 03-07
            /* Console.WriteLine("面包店正在打折，活动进行中......");
             Console.WriteLine("请输入星期：");
             string strWeek = Console.ReadLine();
             Console.WriteLine("请输入时间：");
             int intTime = Convert.ToInt32(Console.ReadLine());
             if (    (strWeek == "星期二" && (intTime >= 19 || intTime <= 20))  ||   (strWeek == "星期六" && (intTime >= 17 || intTime <= 18)) )
             { 
                 Console.WriteLine("恭喜你，你获得了折扣活动参与资格，请尽情选购吧！");
             }
             else
             {
                 Console.WriteLine("对不起，您来晚了一步，赠送您20元代金券，期待下次活动......");
             }
             Console.Read();*/
            #endregion

            #region 03-08
            /*Console.Write("请输入一个年龄：");
            int age = Convert.ToInt32(Console.ReadLine());
            string info = age>40 ? "人到中年了！" : "这是黄金奋斗的年龄";
            Console.WriteLine(info);
            Console.ReadLine();*/
            #endregion

            //------------------------------------------

            #region 04-01
            /*Console.WriteLine("请输入一个数字：");
            int i = Convert.ToInt32(Console.ReadLine());
            if (i%2!=0)
            {
                Console.WriteLine(i + " 是一个奇数");
            }
            else
            {
                Console.WriteLine(i + " 是一个偶数");
            }
            Console.ReadLine();*/
            #endregion

            #region 04-02
            /*Console.WriteLine("请输入一个分数：");
            int score = Convert.ToInt32(Console.ReadLine());
            if (score>90)
            {
                Console.WriteLine("你非常优秀！");
            }
            else
            {
                Console.WriteLine("下次继续努力！");
            }
            Console.ReadLine();*/
            #endregion

            #region 04-03
            /*Console.WriteLine("请输入您的年龄：");
            int age = Convert.ToInt32(Console.ReadLine());
            if (age <= 18)
            {
                Console.WriteLine("您的年龄还小，要努力奋斗哦！");
            }
            else if (age>18 && age<=30)
            {
                Console.WriteLine("您现在的阶段正是努力的黄金阶段！");
            }
            else if (age>30 && age<=50)
            {
                Console.WriteLine("您现在的阶段正是黄金阶段！");
            }
            else
            {
                Console.WriteLine("最美不过夕阳红！");

            }
            Console.ReadLine();*/
            #endregion

            #region 04-04
            /*Console.WriteLine("请输入一个年份：");
            int year = Convert.ToInt32(Console.ReadLine());
            if (year % 4 == 0)
            {
                if (year % 100 == 0)
                {
                    if (year % 400 == 0)
                    {
                        Console.WriteLine("这是闰年");
                    }
                    else
                    {
                        Console.WriteLine("这不是闰年");
                    }
                }
                else
                {
                    Console.WriteLine("这是闰年");
                }
            }
            else
            {
                Console.WriteLine("这不是闰年");
            }
            Console.ReadLine();*/
            #endregion

            #region 04-05
            /*Console.WriteLine("请输入要查询的录取分数线（例民办本科、艺术类本科、体育类本科、二本、一本）：");
            string str = Convert.ToString(Console.ReadLine());
            switch (str)
            {
                case "民办本科":
                    Console.WriteLine("民办本科的录取分数线：350");
                    break;
                case "艺术类本科":
                    Console.WriteLine("艺术类本科的录取分数线：290");
                    break;
                case "体育类本科":
                    Console.WriteLine("体育类本科的录取分数线：280");
                    break;
                case "二本":
                    Console.WriteLine("二本的录取分数线：445");
                    break;
                case "一本":
                    Console.WriteLine("一本的录取分数线：550");
                    break;
                default:
                    Console.WriteLine("您输入的信息有误！");
                    break;
            }
            Console.ReadLine();*/
            #endregion

            #region 04-06
            /*int num_while = 1;
            int sum_while = 0;
            while(num_while <= 100)
            {
                sum_while += num_while;
                num_while++;
            }
            Console.WriteLine("从1加到100 (while)\n" + sum_while);
            Console.ReadLine();*/
            #endregion

            #region 04-07
            /*int num_do = 1;
            int sum_do = 0;
            do
            {
                sum_do += num_do;
                num_do++;
            } while (num_do <= 100);
            Console.WriteLine("从1加到100 (do...while)\n" + sum_do);
            Console.ReadLine();*/
            #endregion

            #region 04-08
            /*int sum_for = 0;
            for (int num=1; num<=100; num++)
            {
                sum_for += num;
            }
            Console.WriteLine("从1加到100 (for)\n" + sum_for);
            Console.ReadLine();*/
            #endregion

            #region 04-09
            /*int iRow, iColumn;
            for (iRow = 1; iRow < 10; iRow++)
            {
                for (iColumn = 1; iColumn <= iRow; iColumn++)
                {
                    Console.Write("{0}*{1}={2}  ", iColumn, iRow, iRow * iColumn);
                }
                Console.WriteLine();
            }
            Console.ReadLine();*/
            #endregion

            #region 04-10 
            /*int num_break = 1;
            int sum_break = 0;
            while (num_break <= 100)
            {
                sum_break += num_break;
                num_break++;
                if (num_break == 50)
                    break; 
            }
            Console.WriteLine("1加到100(加到50时跳出):  "+sum_break);
            Console.ReadLine();*/
            #endregion

            #region 04-11
            /* int sum_continue = 0;

             for (int num_continue = 1;num_continue<=100;num_continue++)
             {
                 if (num_continue % 2 == 1)
                 {
                     continue;
                 }
                 sum_continue += num_continue;
             }
             Console.WriteLine("1到100的偶数和："+sum_continue);
             Console.ReadLine();*/
            #endregion

            //----------------------------------------

            #region 05-01
            /*int[] arr = new int[] { 31, 28, 31, 30, 31, 60, 31, 31, 30, 31, 30, 31 };
            for(int i=0;i<arr.Length;i++)
            {
                Console.Write((i + 1) + "月有" + arr[i] + "天\n");
            }
            Console.ReadLine();*/
            #endregion

            #region 05-02
            /*Console.Title="简单客车售票系统";
            string[,] zuo = new string[9, 4];
            for (int i = 0; i < 9; i++)
            {
                for (int j = 0; j < 4; j++)
                {
                    zuo[i, j] = "【有票】";
                }
            }

            string s = string.Empty;//字符串初始化变量，出初始化为“空”
            while (true)//死循环，保证用户的持续输入
            {
                 Console.Clear();//清空控制台
                 Console.WriteLine("\t简单客车售票系统\n");
                 for (int i = 0; i < 9; i++)
                 {
                     for (int j = 0; j < 4; j++)
                     {
                         Console.Write(zuo[i, j]);
                     }
                     Console.WriteLine();
                 }

                 Console.WriteLine("请输入座位号（例0~9，0~3），如果输入的q，则退出程序：");
                 s = Console.ReadLine();//接收输入
                 if (s == "q")
                 {
                    break;
                 }
                 string[] ss = s.Split(',');//以“，”拆分输入的字符串
                 int row = int.Parse(ss[0]);
                 int column = int.Parse(ss[1]);
                 zuo[row, column] = "【已售】";
            }*/
            #endregion

            #region 05-03
            /*Console.Title="\t杨辉三角:\n";
            int[][] array_int = new int[10][];
            for(int i = 0; i < array_int.Length; i++)
            {
                array_int[i] = new int[i + 1];
                for(int j = 0; j < array_int[i].Length; j++)
                {
                    if (i <= 1)
                    {
                        array_int[i][j] = 1;
                        continue;
                    }//第1,2行，值都为1
                    else
                    {
                        if (j == 0 || j == array_int[i].Length - 1)
                            array_int[i][j] = 1;//行首&行尾为1
                        else
                            array_int[i][j] = array_int[i - 1][j - 1] + array_int[i - 1][j];//算子：上方两数之和
                    }
                }
            }//初始化
            for(int i = 0; i < array_int.Length - 1; i++)
            {
                for(int j=0; j <= array_int.Length; j++)
                {
                    Console.Write(" ");
                }
                for(int k=0;k<array_int[i].Length; k++)
                {
                    Console.Write(array_int[i][k] + " ");
                }
                Console.WriteLine();
            }//输出
            Console.ReadLine();*/
            #endregion

            #region 05-04
            /*Console.WriteLine("输出狼人杀游戏主要身份：");
            string[] roles = { "狼人", "预言家", "村民", "女巫", "丘比特", "猎人", "守卫" };
            foreach(string role in roles)//foreach遍历数组
            {
                Console.Write(role+"  ");
            }
            Console.ReadLine();*/
            #endregion;

            //------------------------------------------

            #region 06-01
            /*string str= "We are the world";
            int first = str.IndexOf("r");
            int second = str.IndexOf("r", first + 1);
            int third = str.IndexOf("r", second + 1);
            Console.WriteLine("r第一次出现的位置:" + first);
            Console.WriteLine("r第二次出现的位置:" + second);
            Console.WriteLine("r第三次出现的位置:" + third);
            Console.ReadLine();*/
            #endregion

            #region 06-02
            /*Console.WriteLine("请输入登录用户名：");
            string name = Console.ReadLine();
            Console.WriteLine("请输入登录密码：");
            string pwd = Console.ReadLine();
            if (name == "zhongxin" && pwd == "zx104104")
            {
                Console.WriteLine("登录成功，欢迎来到议案中心");
            }
            else
            {
                Console.WriteLine("请输入正确的用户名和密码");
            }
            Console.ReadLine();*/
            #endregion

            #region 06-03
            /*Console.WriteLine("1251+3950的结果是(以货币形式显示)：{0:C}",1251+3950);
            Console.WriteLine("120000.1用科学计数器表示：{0:E}",120000.1);
            Console.WriteLine("12800用分隔符数字显示的结果是：{0:NO}",12800);
            Console.WriteLine("Π取两位小数点：{0:F2}",Math.PI);
            Console.WriteLine("33的16进制结果是：{0:X4}",33);
            Console.WriteLine("天才是由{0:P0}的汗水，加上{1:P0}的灵感",0.01,0.09);
            Console.ReadLine();*/
            #endregion

            #region 06-04
            /*DateTime strDate = DateTime.Now;
            Console.WriteLine("当前日期的短日期格式表示{0:d}",strDate);
            Console.WriteLine("当前日期的长日期格式表示{0:D}\n", strDate);
            Console.WriteLine("当前日期的完整日期/时间（短时间）格式表示{0:f}", strDate);
            Console.WriteLine("当前日期的完整日期/时间（长时间）格式表示{0:F}\n", strDate);
            Console.WriteLine("当前日期的常规日期/格式（短时间）表示{0:t}", strDate);
            Console.WriteLine("当前日期的常规日期/格式（长时间）表示{0:T}\n", strDate);
            Console.WriteLine("当前日期的月/日格式表示{0:M}", strDate);
            Console.WriteLine("当前日期的年/月日期格式表示{0:Y}\n", strDate);

            Console.ReadLine();*/
            #endregion

            #region 06-05
            /*string str = "Program.cs";
            Console.WriteLine("文件完整名称：" + str);
            string name = str.Substring(0, str.IndexOf('.'));//Substring截取字符
            string extension = str.Substring(str.IndexOf('.'));
            Console.WriteLine("文件名：" + name);
            Console.WriteLine("扩展名：" + extension);
            Console.ReadLine();*/
            #endregion

            #region 06-07
            /* string old = "one world，one dream";
             Console.WriteLine("原始字符串："+old);
             string new1 = old.Replace(",", "*");//.Replace字符串替换
             Console.WriteLine("\n第一种形式的替换："+new1);
             string new2 = old.Replace("one", "ONE");
             Console.WriteLine("\n第二种形式的替换："+new2);*/
            #endregion

            #region 06-08
            /*int num = 368;
            StringBuilder sBuilder = new StringBuilder("明日科技");
            sBuilder.Append("》C#编程词典");             //Append 后方追加字符串
            Console.WriteLine(sBuilder);
            sBuilder.AppendFormat("{0:C0}", num);        //AppendFormat 替换字符串
            Console.WriteLine(sBuilder);
            sBuilder.Insert(0, "软件：");                  //Insert 插入字符串
            Console.WriteLine(sBuilder);
            sBuilder.Remove(14, sBuilder.Length - 14);   //Remove 删除
            Console.WriteLine(sBuilder);
            sBuilder.Replace("软件：", "软件工程师必备：");  //Replace 插入字符串（相同字符将替换）
            Console.WriteLine(sBuilder);
            Console.ReadLine();*/
            #endregion

            //------------------------------------

            #region 07-01
            /*Console.WriteLine("请输入半径：");
            r = Convert.ToDouble(Console.ReadLine());
            Console.WriteLine("圆面积为：" + PI * Math.Pow(r, 2));
            Console.ReadLine();*/
            #endregion

            #region 07-02
            /*Program p = new Program();
            while (true)
            {
                Console.WriteLine("请输入年龄：");
                p.Age = Convert.ToInt32(Console.ReadLine());
            }*/
            #endregion

            #region 07-03
            /*Program pro1 = new Program();
            Program pro2 = new Program();
            Program pro3 = new Program();
            Console.ReadLine();*/
            #endregion

            #region 07-04
            /*Program p = new Program();
            int x = 30, y = 40;
            Console.WriteLine("值参数的使用：" + p.Add(x, y));
            Console.WriteLine("值参数的使用：" + x);
            Console.WriteLine("ref参数的使用：" + p.Add(ref x, y));
            Console.WriteLine("ref参数的使用：" + x);
            Console.WriteLine("out参数的使用：" + p.Add(x, y,out int z));
            Console.WriteLine("params参数的使用：" + p.Add(20,30,40,50,60,70));
            Console.ReadLine();*/
            #endregion

            #region 07-05
            /*Program p = new Program();
            int x = 3, y = 5, z = 7;
            double y2 = 5.5;
            Console.WriteLine("第一种重载形式" + Program.Add(x, y));
            Console.WriteLine("第二种重载形式" + p.Add(x, y2));
            Console.WriteLine("第三种重载形式" + p.Add(x, y, z));
            Console.ReadLine();*/
            #endregion

            #region 07-07
            /*cStookInfo info = new cStookInfo();
            info.FullName = "笔记本电脑";
            info.ShowGoods();
            Console.ReadLine();*/
            #endregion

            #region 07-08
            /*JHInfo info = new JHInfo();
            info.JHID = "JH100001";
            info.TradeCode = "001";
            info.FullName = "笔记本电脑";
            info.ShowInfo();
            Console.ReadLine();*/
            #endregion

            #region 07-09
            /*Computer com = new Computer();
            Pad pad = new Pad();
            Console.WriteLine(com.sayHello());
            Console.WriteLine(pad.sayHello());
            Console.ReadLine();*/
            #endregion

            #region 07-10
            /*Vehicle v = new Vehicle();
            train t = new train();
            Car c = new Car();
            Vehicle[] vs = { v, t, c };//子类对象向上转型，可对子类进行赋值
            v.Name = "交通工具";
            t.Name = "火车";
            c.Name = "汽车";
            vs[0].Move();
            vs[1].Move();
            vs[2].Move();
            Console.ReadLine();*/
            #endregion

            #region 07-11
            /*Market wall = new WallMarket();
            wall.Name = "沃尔玛";
            wall.Goods = "七匹狼西服";
            wall.Shop();
            Market taobao = new WallMarket();
            wall.Name = "淘宝";
            wall.Goods = "韩都衣舍";
            wall.Shop();
            Console.ReadLine();*/
            #endregion

            #region 07-12
            /*IPerson[] persoon = new IPerson[] { new Student(), new Teacher() };
            persoon[0].Name = "peter";
            persoon[0].Age = 20;
            persoon[1].Name = "mike";
            persoon[1].Age = 40;
            persoon[0].Speek();
            persoon[1].Speek();
            Console.WriteLine();
            persoon[0].Work();
            persoon[1].Work();
            Console.ReadLine();*/
            #endregion

            #region 14-01
            /*string ip, name, localip = "127.0.0.1";
            string localname = Dns.GetHostName();
            IPAddress[] ips = Dns.GetHostAddresses(localname);
            foreach (IPAddress ip1 in ips)
            {
                if (!ip1.IsIPv6SiteLocal)
                {
                    localip = ip1.ToString();
                }
                else
                {

                }
            }
            Console.WriteLine("本机名：" + localname + "   本机IP地址" + localip);
            for(int i = 50; i <= 60; i++)
            {
                ip = "192.168.1." + i;
                try
                {
                    IPHostEntry host = Dns.GetHostEntry(ip);
                    name = host.HostName;
                    Console.WriteLine("IP地址" + ip + "  对应的主机名称是：" + name);
                }
                catch
                {
                    Console.WriteLine("没有该主机！");
                }
            }*/
            #endregion

            #region 15-04
            Program p = new Program();
            Thread t1 = new Thread(new ThreadStart(p.Ticket));
            t1.Name = "线程一";
            Thread t2 = new Thread(new ThreadStart(p.Ticket));
            t2.Name = "线程二";
            Thread t3 = new Thread(new ThreadStart(p.Ticket));
            t3.Name = "线程三";
            Thread t4 = new Thread(new ThreadStart(p.Ticket));
            t4.Name = "线程四";
            t1.Start();
            t2.Start();
            t3.Start();
            t4.Start();
            #endregion
        }
        #region 07-01
        /* static double r;
         const double PI = 3.14;*/
        #endregion

        #region 07-02  
        /*private int age;
        public int Age
        {
            get
            {
                return age;
            }
            set
            {
                if (value > 0 && value < 150)
                {
                    age = value;
                }
                else
                {
                    Console.WriteLine("输入数据不合理！");
                }
            }
        }*/
        #endregion

        #region 07-03
        /*static Program()//静态构造函数 只执行一次
        {
            Console.WriteLine("static");
        }
        private Program()//实例构造函数 建几个执行几次
        {
            Console.WriteLine("实例构造函数");
        }*/
        #endregion

        #region 07-04
        /*int Add(int x, int y)//x实参不变
        {
            x = x + y;
            return x;
        }
        int Add(ref int x, int y)//x实参改变
        {
            x = x + y;
            return x;
        }
        int Add(int x, int y,out int z)//out用法
        {
            z = x + y;
            return z;
        }
        int Add(params int[] x)//数组方法
        {
            int result = 0;
            for(int i = 0; i < x.Length; i++)
            {
                result += x[i];
            }
            return result;
        }*/
        #endregion

        #region 07-05
        /*static int Add(int x,int y)
        {
            return x + y;
        }
        double Add(int x, double y)
        {
            return x + y;
        }
        int Add(int x, int y,int z)
        {
            return x + y + z;
        }*/
        #endregion

        #region 07-07
        /*class cStookInfo
        {
            public string FullName
            {
                get;
                set;
            }
            public void ShowGoods()
            {
                Console.WriteLine("库存商品名称：");
                Console.WriteLine(FullName);
            }
        }*/
        #endregion

        #region 07-08
        /*class Goods
        {
            public string TradeCode
            {
                get;
                set;
            }
            public string FullName
            {
                get;
                set;
            }
        }
        class JHInfo : Goods
        {
            public string JHID
            {
                get;
                set;
            }
            public void ShowInfo()
            {
                Console.WriteLine("进货编号：{0}\n商品编号：{1}\n商品名称：{2}",JHID,TradeCode,FullName);
            }
        }*/
        #endregion

        #region 07-09
        /*class Computer
        {
            public string sayHello()
            {
                return "欢迎使用";
            }
        }
        class Pad:Computer
        {
            public new string sayHello()
            {
                return base.sayHello() + "平板电脑";
            }
        }*/
        #endregion

        #region 07-10
        /*class Vehicle
        {
            string name;
            public string Name
            {
                get
                {
                    return name;
                }
                set
                {
                    name = value;
                }
            }
            public virtual void Move()//父类虚方法
            {
                Console.WriteLine("{0}都可以移动", Name);
            }
        }
        class train : Vehicle
        {
            public override void Move()//重写虚方法
            {
                Console.WriteLine("{0}可以在铁轨上行驶", Name);
            }
        }
        class Car : Vehicle
        {
            public override void Move()
            {
                Console.WriteLine("{0}可以在公路上行驶", Name);
            }
        }*/
        #endregion

        #region 07-11
        /*public abstract class Market//抽象类
        {
            public string Name { get; set; }
            public string Goods { get; set; }
            public abstract void Shop();//抽象方法,无{}
        }
        public class WallMarket : Market//继承抽象类，必须实现抽象方法
        {
            public override void Shop()
            {
                Console.WriteLine(Name+"购买"+Goods);
            }
        }
        public class TaobaoMarkrt : Market
        {
            public override void Shop()
            {
                Console.WriteLine(Name + "购买" + Goods);
            }
        }*/
        #endregion

        #region 07-12
        /*interface IPerson//接口 ，默认属性方法—公共，不需要加访问修饰符
        {
            string Name { get; set; }
            int Age { get; set; }
            void Speek();
            void Work();
        }
        class Student : IPerson
        {
            public string Name { get; set; }
            public int Age { get; set; }
            public int age
            {
                get
                {
                    return age;
                }
                set
                {
                    if (age > 0 || age < 150)
                    {
                        age = value;
                    }
                }
            }
            public void Speek()
            {
                Console.WriteLine(Name + "：老师好");
            }

            public void Work()
            {
                Console.WriteLine(Name + "：同学开始记笔记");
            }
        }
        class Teacher : IPerson
        {
            public string Name { get; set; }
            public int Age { get; set; }
            public int age
            {
                get
                {
                    return age;
                }
                set
                {
                    if (age > 0 || age < 150)
                    {
                        age = value;
                    }
                }
            }
            public void Speek()
            {
                Console.WriteLine(Name + "：同学们好");
            }

            public void Work()
            {
                Console.WriteLine(Name + "：老师开始上课");
            }
        }*/
        #endregion

        #region 15-04
        int num = 10;
        void Ticket()
        {
            while (true)
            {
                lock (this)
                {
                    if (num > 0)
                    {
                        Thread.Sleep(100);
                        Console.WriteLine(Thread.CurrentThread.Name + "---票数" + num--);
                    }
                }
            }
        }
        #endregion
    }
}
